<?php

require_once("../db/db.php");

class Corpus {
	
	public function getCorpuses() {
		
		$db = new Database();
		
		$result = $db->executeQuery("SELECT * FROM corpus");
		$result = $db->parseIntegers($result, "id");
		
		return $result;
	}
	
	public function addCorpus($name) {
		
		$db = new Database();
		
		$result = $db->executeQuery("SELECT * FROM corpus WHERE name='" . $name . "'");
		
		$doesNotExist = count($result) == 0;
		
		$newId = $db->getMax("corpus", "id", true) + 1;
		
		if ($doesNotExist) {
			$db->executeQuery("INSERT INTO corpus(id, name) VALUES ('" . $newId . "', '" . $name . "')");
			return true;
		}
		else {
			return false;
		}
	}	
}	
?>